package com.qfxl.common.entity.base;

import lombok.Data;

/**
 * 统一响应体
 */
@Data
public class ObjectRest {
    String message;

    Integer code;

    Object data;

    RestCommEnum restCommEnum;

    Object countSize;

    public static ObjectRest rest(Object data, RestCommEnum restCommEnum) {
        ObjectRest objectRest = new ObjectRest();
        objectRest.setCode(restCommEnum.getCode());
        objectRest.setMessage(restCommEnum.getMessage());
        objectRest.setData(data);
        return objectRest;
    }

    public static ObjectRest rest(Object data) {
        ObjectRest objectRest = new ObjectRest();
        objectRest.setCode(RestCommEnum.SUCCESS.getCode());
        objectRest.setMessage(RestCommEnum.SUCCESS.getMessage());
        objectRest.setData(data);
        return objectRest;
    }

    public static ObjectRest rest(Object data, String message) {
        ObjectRest objectRest = new ObjectRest();
        objectRest.setCode(200);
        objectRest.setMessage(message);
        objectRest.setData(data);
        return objectRest;
    }

    public static ObjectRest rest(Object data, String message, Object countSize) {
        ObjectRest objectRest = new ObjectRest();
        objectRest.setCode(200);
        objectRest.setMessage(message);
        objectRest.setData(data);
        objectRest.setCountSize(countSize);
        return objectRest;
    }

    public static ObjectRest success() {
        ObjectRest objectRest = new ObjectRest();
        objectRest.setCode(200);
        objectRest.setMessage("操作成功");
        return objectRest;
    }

    public static ObjectRest error(Object data, String message) {
        ObjectRest objectRest = new ObjectRest();
        objectRest.setCode(500);
        objectRest.setMessage(message);
        objectRest.setData(data);
        return objectRest;
    }

    public static ObjectRest error(Object data, RestCommEnum restCommEnum) {
        ObjectRest objectRest = new ObjectRest();
        objectRest.setCode(restCommEnum.getCode());
        objectRest.setMessage(restCommEnum.getMessage());
        objectRest.setData(data);
        return objectRest;
    }


}
